TestCase("TodoListAllTest", sinon.testCase({
    setUp: function () {
        this.todoList = new tddjs.TodoList();
    },

    "test should GET /todo-items": function () {
        this.todoList.all(function () {});

        assertEquals(1, this.requests.length)
        assertEquals("GET", this.requests[0].method)
        assertEquals("/todo-items", this.requests[0].url)
    },

    "test should call callback with data from server": function () {
        var callback = sinon.spy();

        this.todoList.all(callback);
        this.requests[0].respond(
            200, { "Content-Type": "application/json" },
            '[{"text":"Brush","done":false,"id":1}]');

        sinon.assert.calledOnce(callback);
        sinon.assert.calledWith(
            callback, null, [{"text":"Brush","done":false,"id":1}]);
    },

    "test should call callback with error when server fails": function () {
        var callback = sinon.spy();

        this.todoList.all(callback);
        this.requests[0].respond(
            500, { "Content-Type": "text/plain" },
            'Server do bad');

        sinon.assert.calledOnce(callback);
        sinon.assert.calledWith( callback, { message: "500: Server do bad" });
    },

    "test should call callback for marking as done": function () {
        var callback = sinon.spy();

        this.todoList.completeItem(0, callback);
        this.requests[0].respond(
            200, { "Content-Type": "application/json" },
     		'[{}]');

        sinon.assert.calledOnce(callback);
        sinon.assert.calledWith(
            callback, null, null);
        assertEquals(1, this.requests.length)
        assertEquals("POST", this.requests[0].method)
        assertEquals("/todo-items/0", this.requests[0].url)
    },

    "test should mot call callback for marking as done on server error": function () {
        var callback = sinon.spy();
        this.todoList.completeItem(0, callback);
        
        this.requests[0].respond(
            500, { "Content-Type": "text/plain" },
     		'Exception');

        sinon.assert.calledOnce(callback);
        sinon.assert.calledWith(
            callback, {message : "bad server"}, null);
    }
}));
